<%--
  Created by IntelliJ IDEA.
  User: 陈大神
  Date: 2020/4/3
  Time: 12:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>json</title>
    <button id="btn">发送请求</button>
</head>
<body>

<script src="scripts/jquery-3.4.1.js"></script>
<script>
    $(function () {
        $("#btn").click(function () {
            var user = {"id": 1001, "username": "haoren01", "pwd": "250"};
            $.ajax({
                type: "post",
                url: "reqJsonTest",
                data: JSON.stringify(user), //响应给服务器的应该是一个符合json格式的字符串
                contentType: "application/json;charset=utf-8",
                success: function (data) {
                    console.log(data);
                }
            });
        });
        /*  $.post("reqJsonTest",JSON.stringify(user),function(data){
                 console.log(data);
           });*/
    });
</script>
</body>
</html>
